Title: SQL W3S (By-BKK) / 039 Case
Tags: Obsidian_to_Anki

Q: What does the SQL CASE expression do?
A: It evaluates conditions and returns a value based on the first true condition

Q: True/False: The SQL CASE expression stops reading conditions after the first true condition is found.
A: True

Q: If no WHEN condition matches and there is no ELSE in a CASE expression, what does SQL return?
A: NULL

Q: What keyword is used in a CASE expression to provide a default value if no conditions are met?
A: ELSE

Q: Write the syntax for a simple CASE expression in SQL.
A: CASE
  WHEN condition1 THEN result1
  WHEN condition2 THEN result2
  ...
  ELSE result
END

Q: How does SQL CASE behave like programming statements?
A: It works like an if-then-else statement

Q: Give an example: Assign text based on Quantity using CASE.
A: CASE
  WHEN Quantity > 30 THEN 'The quantity is greater than 30'
  WHEN Quantity = 30 THEN 'The quantity is 30'
  ELSE 'The quantity is under 30'
END

Q: When using CASE in ORDER BY, how can you sort by City and Country if City is NULL?
A: ORDER BY (CASE WHEN City IS NULL THEN Country ELSE City END)

Q: Which clause is used for conditional logic inside SQL SELECT statements?
A: CASE

Q: CASE is used for conditional logic in SQL SELECT statements.
A: Which clause allows you to include conditions in SELECT statements?

Q: CASE expressions can be used in ORDER BY clauses.
A: True

Q: True/False: CASE expressions can only be used with numeric values.
A: False

Q: What does the THEN part of a CASE expression do?
A: Returns a value when its condition is true

Q: What happens if multiple WHEN conditions in CASE are true?
A: Only the first true condition’s THEN value is returned

Q: True/False: CASE expressions can be nested inside other CASE expressions.
A: True

Q: In SQL, CASE returns what if all conditions are false and there is an ELSE statement?
A: The value after ELSE

Q: CASE stops checking further conditions after finding a true condition.
A: True

Q: Reverse card:
NULL is returned if no CASE condition matches and there is no ELSE.
A: What does SQL return if all CASE conditions fail and there is no ELSE clause?

Q: Reverse card:
It evaluates conditions and returns a value based on the first true condition.
A: What is the main purpose of the SQL CASE expression?

Q: Reverse card:
CASE expressions can be used in SELECT, ORDER BY, and WHERE clauses.
A: Where can SQL CASE expressions be used?